<template>
  <div>
    <el-table
      :data="catelist"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="分类编号" width="100"></el-table-column>
      <el-table-column prop="catename" label="分类名称"></el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <img :src="$pre+scope.row.img" alt />
        </template>
      </el-table-column>
      <el-table-column prop="address" label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="change(scope.row.id)">修改</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { reqcatedelete } from "../../../request/api.js";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      info: "cate/info",
      catelist: "cate/catelist"
    })
  },
  methods: {
    ...mapActions({
      reqcatelist: "cate/catelist",
      reqcateinfo: "cate/cateinfo"
    }),
    change(id) {
      this.info.isadd = false;
      this.info.isshow = true;
      this.reqcateinfo({ id: id });
    },
    del(id) {
      reqcatedelete({ id: id });
      this.reqcatelist();
    }
  },
  mounted() {
    this.reqcatelist();
  }
};
</script>

<style scoped>
img {
  width: 100px;
  height: 100px;
}
</style>